home *** CD-ROM | disk | FTP | other *** search
/ Mac-Source 1994 July / Mac-Source_July_1994.iso / C and C++ / Utilities / Winter Shell 1.0d2 / Source / Libraries / PreferencesLib / PreferencesLib.c next >
Encoding:
C/C++ Source or Header  |  1994-01-17  |  1.1 KB  |  56 lines  |  [TEXT/KAHL]

  1. /* Functions for accessing the preferences file.
  2.     93/12/16 aih created */
  3.  
  4. #include "ApplicationLib.h"
  5. #include "FileLib.h"
  6. #include "FinderLib.h"
  7. #include "PreferencesLib.h"
  8. #include "ResourceConstantsLib.h"
  9. #include "ResourceLib.h"
  10.  
  11. static FileRefType gPrefsReference = FILE_CLOSED;
  12.  
  13. FileType *PrefsFile(void)
  14. {
  15.     volatile FileRefType ref = FILE_CLOSED;
  16.     static Boolean initialized;
  17.     static FileType file;
  18.     FileNameType name;
  19.     
  20.     TRY {
  21.         if (! initialized) {
  22.             ResStrLen(RLS_FILE, RLS_FILE_PREFERENCES, name, sizeof(FileNameType));
  23.             FileSetPref(&file, name);
  24.             if (! FileExists(&file)) {
  25.                 FileCreate(&file, AppCreator(), 'PREF');
  26.                 ResFileCreate(&file);
  27.                 ref = ResFileOpen(&file, fsWrPerm);
  28.                 FinderWriteDefaultMessage(RLS_FINDER_PREFS);
  29.                 ResFileClose(ref);
  30.                 ref = FILE_CLOSED;
  31.             }
  32.             initialized = true;
  33.         }
  34.     } CATCH {
  35.         ResFileClose(ref);
  36.     } ENDTRY;
  37.     return(&file);
  38. }
  39.  
  40. short PrefsReferenceNumber(void)
  41. {
  42.     return(gPrefsReference);
  43. }
  44.  
  45. void PrefsOpen(void)
  46. {
  47.     require(gPrefsReference == FILE_CLOSED);
  48.     gPrefsReference = ResFileOpen(PrefsFile(), fsCurPerm);
  49. }
  50.  
  51. void PrefsClose(void)
  52. {
  53.     ResFileClose(gPrefsReference);
  54.     gPrefsReference = FILE_CLOSED;
  55. }
  56.